<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML>
<html>
<head>
<title>权限管理</title>
<meta name="description" content="组织机构管理">
<meta name="content-type" content="text/html; charset=UTF-8">
<script src="${pageContext.request.contextPath}/js/miniui/scripts/boot.js" type="text/javascript"></script>
<style type="text/css">
body {
	margin: 0;
	padding: 0;
	border: 1;
	width: 100%;
	height: 100%;
	overflow: hidden;
}
/*权限复选框样式*/
.rTree {
	background-repeat: no-repeat;
	background-position: 0 1px;
	width: 16px;
	height: 18px;
	display: inline-block;
	overflow: hidden;
	vertical-align: middle;
	-moz-user-select: none;
	-webkit-user-select: none;
	-ms-user-select: none;
	-khtml-user-select: none;
	user-select: none;
}

.rCheckBoxText {
	height: 20px;
	vertical-align: top;
	overflow: hidden;
	display: inline-block;
}

.rNoUnChecked {
	background-image: url(no_unchecked.gif);
}

.rNoChecked {
	background-image: url(no_checked.gif);
}

.rChecked {
	background-image: url(checked.gif);
}

.rUnChecked {
	background-image: url(unchecked.gif);
}

.header {
	background: url(/HTOA/js/miniui/demo/header.gif) repeat-x 0 -1px;
}
</style>
<script type="text/javascript">
	var gRootId = "";
	$().ready(function() {
		LoadOrgTree();
		CreateRoleTree();
	});

	/*
		描述:关闭窗口
	 */
	function goCloseDlg(name) {
		var oWinDlg = mini.get(name);
		oWinDlg.setUrl("about:blank");
		$(oWinDlg.getBodyEl()).html("");
		$(oWinDlg.getFooterEl()).html("");
		oWinDlg.hide();
	}
	/*
		描述:创建部门树
	 */
	function LoadOrgTree() {
		//异步加载数据，去掉数据最前端的逗号，使得tree数据格式正确。
		$.ajax({
			url : "/HTOA/admin/findOrgTree.action",
			cache : false,
			dataType : "text",
			success : function(data) {
				var orgData = mini.decode(data);
				if (orgData) {
					gOrgTree.loadList(orgData, "id", "pid");
					gOrgTree.expandLevel(0);
				} else {
					gOrgTree.loadList([], "id", "pid");
				}
			}
		});
	}

	function goTabChange(e) {
		var  oCurTab = e.tab;
		gRootId = oCurTab.name;
		loadMenuTreeNode();

	}
	
	function loadMenuTreeNode(){
		var strPath = "";
		strPath = "/HTOA/admin/findMenuTreeNodeList.action";
		$.post(strPath, {
			"menu.menuRootId" : gRootId
		}, function(data) {
			var list = mini.decode(data);
			mini.get("MenuTree" + gRootId).loadList(list, "id", "pid");
		});
	}
	
	function goDrawNode(e) {
		/*
		var tree = e.sender;
		var node = e.node;
		var strClassName="";
		switch(node.status){
			case 0:
				strClassName=("rTree rNoUnChecked");
				break;
			case 1:
				strClassName=("rTree rUnChecked");
				break;
			case 2:
				strClassName=("rTree rChecked");
				break;
			default:
				strClassName=("rTree rNoChecked");
		}
		if(gRootId=="GridTree"){
			if(!e.isLeaf){		
				strClassName=("rTree rNoChecked");
			}
		}
		e.nodeHtml = '<span id="' + node.id + '" onclick=\'goCheckBox("'+tree.id+'")\' class="'+strClassName+'"></span><span class="rCheckBoxText">' + node.text + '</span>';
		
		 */
	}

	/*
		描述:加载角色列表
	 */
	function CreateRoleTree() {
		$.ajax({
			url : encodeURI("/HTOA/admin/findAllRoleJson.action"),
			type : "post",
			data : {},
			dataType : "text",
			success : function(data) {
				if (data) {
					var list = mini.decode(data);
					gRoleTree.loadList(list, "id", "pid");
				}
			}
		});
	}
	function goMenu(e) {
		var strURL = "", strTitle = "", pid = "", tabId = "", intWidth = 700, intHeight = 500;
		if (typeof (e.node) == "undefined") {
			var menuListTree = mini.get("MenuTree" + gRootId);
			var node = menuListTree.getSelectedNode();
			if (node) {
				pid = node.id;
				tabId = node.rootId;
			}
			strTitle = "\u65B0\u5EFA";
			strURL = "/HTOA/right/menu.jsp?pid=" + pid + "&rootId=" + tabId;
		} else {
			intHeight = 500;
			strDocID = e.node.id;
			strTitle = "\u7EF4\u62A4";
			if(e.node.type=="Menu"){
				strURL = "/HTOA/admin/findMenuById.action?menu.uuid=" + strDocID;
			}else{
				strURL = "/HTOA/admin/findMenuBtnById.action?menuToBtn.uuid=" + strDocID;
			}
		}
		var oWinDlg = mini.get('oWinDlg');
		if (oWinDlg == null) {
			oWinDlg = mini.open({
				id : "oWinDlg",
				showMaxButton : true,
				headerStyle : "font-weight:bold;letter-spacing:4px",
				footerStyle : "padding:5px;height:25px"
			});
		}
		oWinDlg.setUrl(strURL);
		oWinDlg.setTitle(strTitle);
		oWinDlg.setWidth(intWidth);
		oWinDlg.setHeight(intHeight);
		oWinDlg.showAtPos("center", "middle");
	}
</script>
</head>
<body>
	<div class="mini-splitter" style="width:100%;height:100%;border:0" vertical="true" allowResize="false">
		<div size="60" showCollapseButton="true" class="header">
			<h1 style="margin:0;padding:15px;font-family:微软雅黑,黑体,宋体;">权限管理</h1>
			<div style="position:absolute;top:35px;left:180px;font-size:12px">版本:V1.0</div>
		</div>
		<div showCollapseButton="false" style="border:0">
			<div class="mini-layout" style="width:100%;height:100%;" id="layout">
				<div region="west" style="overflow:hidden;border-bottom:0" showHeader="false" width="200px" minWidth="200" maxWidth="350" showSplitIcon="true">
					<div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;">
						<table style="width:100%" cellspacing=0 cellpadding=0>
							<tr>
								<td style="width:100%;text-align:center"><input id="key" class='mini-textbox' style="width:98%" onenter="Search" /></td>
								<td style="white-space:nowrap;">&nbsp;&nbsp; <a class='mini-button' iconCls='icon-search' plain='true' style="width:60px" onclick="Search">查询</a>
								</td>
							</tr>
						</table>
					</div>
					<div class="mini-fit" style="padding:2px;border-top:0;border-left:0;border-right:0;">
						<div id="OrgTabs" class="mini-tabs" style="height:100%;" plain="false">
							<div title="组织机构">
								<div id='OrgTree' class='mini-tree' showTreeIcon='true' textField="text" resultAsTree='false' showCheckBox='false' checkRecursive='true' expandOnLoad='0' expandOnDblClick='false'></div>
							</div>
							<div title="角色">
								<ul id='RoleTree' class='mini-tree' showTreeIcon='true' textField="text" resultAsTree='false' showCheckBox='false' checkRecursive='true' expandOnLoad='0' expandOnDblClick='false'
									allowSelect='true' enableHotTrack='false'></ul>
							</div>
						</div>
					</div>
				</div>

				<div region="center" style="overflow:hidden;border-bottom:0;border-right:1">

					<div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;">
						<a class="mini-button" iconCls="icon-tip" plain="true"></a> <span id="divAssigner" style="display:inline-block">无分配对象，双击 &lt; <b>左侧&nbsp;组织机构或角色</b> &gt; 进行分配。
						</span> <span class='separator'></span> <a id="barAddMenu" class="mini-button" iconCls="icon-add" plain="true" onclick="goMenu">添加菜单</a> <a id="barOutMenu" class="mini-button" iconCls="icon-download"
							plain="true" onclick="goExport" visible="true">导出菜单</a> <a id="barInMenu" class="mini-button" iconCls="icon-upload" plain="true" onclick="goImport" visible="true">导入菜单</a> <a id="barMenuInit"
							class="mini-button" iconCls="icon-upload" plain="true" onclick="goInit" visible="false">菜单初始化</a> <a id="barAddRole" class="mini-button" iconCls="icon-add" plain="true" onclick="goRole"
							visible="false">添加角色</a> <a id="barImportRole" class="mini-button" iconCls="icon-user" plain="true" onclick="goImportRole" visible="false">引入角色</a> <a id="barAddGrid" class="mini-button"
							iconCls="icon-add" plain="true" onclick="goGrid" visible="false">添加视图</a> <a class="mini-button" iconCls="icon-save" plain="true" onclick="goSave" visible="true">保存权限</a> <a class="mini-button"
							iconCls="icon-reload" plain="true" onclick="window.location.reload()">刷新</a>
					</div>

					<div class="mini-fit" style="padding:2px;border-top:0;border-left:0;border-right:0;">
						<div id="tabMenu" class="mini-tabs" tabPosition="top" style="height:100%;" plain="false" onactivechanged="goTabChange">
							<c:if test="${not empty menuList}">
								<c:forEach items="${menuList}" var="menu" varStatus="index">
									<div title='${menu.menuName}' name='${menu.menuRootId }' iconCls='icon-folder'>
										<ul id='MenuTree${menu.menuRootId }' class='mini-tree' resultAsTree='false' showCheckBox='false' expandOnLoad="true" checkRecursive='false' contextMenu='#treeMenu' expandOnDblClick='false'
											ondrawnode='goDrawNode' autoCheckParent='false' onnodedblclick='goMenu' imgPath='${pageContext.request.contextPath}/js/miniui/scripts/miniui/themes/icons/'></ul>
									</div>
								</c:forEach>
							</c:if>
							<div title='个人办公' name='个人办公' iconCls='icon-folder'>
								<ul id='MenuTree个人办公' class='mini-tree' resultAsTree='false' showCheckBox='false' checkRecursive='false' contextMenu='#treeMenu' expandOnDblClick='false' ondrawnode='goDrawNode'
									autoCheckParent='false' onnodedblclick='goMenu' imgPath='${pageContext.request.contextPath}/js/miniui/scripts/miniui/themes/icons/'></ul>
							</div>
						</div>
					</div>

				</div>

			</div>
		</div>
	</div>
	<script type="text/javascript">
		mini.parse();
		var gOrgTree = mini.get("OrgTree");
		var gRoleTree = mini.get("RoleTree");
	</script>
</body>
</html>
